import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashSet;


public class MotCle implements Serializable {
	
	
	// ************************************************************************************************************
	// Attributs
	// ************************************************************************************************************

	private static final long serialVersionUID = 1L;
	
	private String _mot;
	private HashSet<Document> _documents;
	
	public MotCle(String mot) {
		this._mot=mot;
		_documents = new HashSet<Document>() ;
	} 

	public String getMot() {
		return _mot;
	}
	
	public HashSet<Document> getDocuments(){
		return this._documents;
	}
	
	public void ajoutDocument(Document d) {
		_documents.add(d);
	}
	
	public void supprimeDocument(Document d) {
		_documents.remove(d);
	}
	
	public boolean exist() {
		boolean b = false;

			try  {
				BufferedReader in = new BufferedReader(
							new FileReader("ListeAutorite.txt"));
				String ligne;
				while ((ligne= in.readLine()) != null)  {
					if(ligne == this._mot){
						b = true;
					}
				}
				in.close();
				
				return b;
			}

			catch (IOException e) {
			 	System.out.println("$$$$$ PB de Lecture dans le fichier ListeAutorite ");
				System.out.println();
				return false;
			}
	}
	
	public Document getDocument(String titre, String type) {
		for (Document d : _documents) {
			if ( d.getTitre().contentEquals(titre) && type.contentEquals(d.getClass().getName()) )
				return d;
		}
		return null;
	}

}
